var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var poststylus = require('poststylus');
var CopyWebpackPlugin = require('copy-webpack-plugin')

module.exports = {
  devtool: 'cheap-module-source-map',
  entry: {
		app: [
			'./src/index'
		],
		ui: [
			'./src/ui.js'
		],
		auth: [
			'./src/auth/index'
		],
    admin: [
      './src/admin/index'
    ],
    util: [
			'./src/utilRoot.js'
    ],
    onboarding: [
			'./src/onboarding.js'
    ],
    charts: [
      './src/charts/index'
    ],
    polyfill: [
      'babel-polyfill',
    ]
	},
  output: {
    path: path.join(__dirname, 'static'),
    filename: '[name].js',
    publicPath: '/static/'
  },
  plugins: [
    new ExtractTextPlugin('[name].css', { allChunks: true, disable: false }),
    new CopyWebpackPlugin([
      { from: './src/images', to: './images' },
    ]),
		new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development'),
        DEV: JSON.stringify(process.env.DEV || 'production'),
      }
		})
  ],
  resolve: {
    extensions: ['', '.js', '.jsx', '.styl', '.css']
  },
	stylus: {
		use: [
			poststylus([ 'autoprefixer', 'rucksack-css' ])
		]
	},
  module: {
		loaders: [
			{
				test: /\.jsx?$/,
				loaders: [ 'babel' ],
        include: path.join(__dirname, 'src'),
			},
      {
        test: /\.css$/,
        loader: ExtractTextPlugin.extract('style', 'css')
      },
			{
				test: /\.styl$/,
        loader: ExtractTextPlugin.extract('style', 'css?sourceMap&modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!postcss!stylus?sourceMap'),
			},
      {
        test   : /\.(ttf|eot|svg|woff)$/,
        loader : 'file-loader'
      },
      {
        test : /\.json$/,
        loader: 'json-loader'
      }
		]
  }
};
